package net.xuzhen97.distributed.transaction.order.service;

import net.xuzhen97.distributed.transaction.order.service.dto.OrderAddCmd;
import net.xuzhen97.distributed.transaction.order.service.dto.OrderPayCompleteCmd;
import net.xuzhen97.distributed.transaction.order.service.dto.OrderPayCompleteConsistencyCmd;
import net.xuzhen97.distributed.transaction.order.service.executor.OrderAddCmdExe;
import net.xuzhen97.distributed.transaction.order.service.executor.OrderPayCompleteCmdExe;
import net.xuzhen97.distributed.transaction.order.service.executor.OrderPayCompleteConsistencyCmdExe;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderService {

    @Resource
    private OrderAddCmdExe orderAddCmdExe;
    @Resource
    private OrderPayCompleteCmdExe orderPayCompleteCmdExe;
    @Resource
    private OrderPayCompleteConsistencyCmdExe orderPayCompleteConsistencyCmdExe;

    /**
     * 创建订单
     * @param cmd
     * @return 订单id
     */
    public String addOrder(OrderAddCmd cmd){
        return orderAddCmdExe.execute(cmd);
    }

    /**
     * 订单完成支付
     * @param cmd
     * @return 订单id
     */
    public String updatePayOrder(OrderPayCompleteCmd cmd){
        return orderPayCompleteCmdExe.execute(cmd);
    }

    /**
     * 订单完成支付，rocketmq事务消息实现
     * @param cmd
     * @return
     */
    public String updatePayOrderConsistency(OrderPayCompleteConsistencyCmd cmd){
        return orderPayCompleteConsistencyCmdExe.execute(cmd);
    }
}
